package enums.learn;

import com.alibaba.fastjson2.JSONReader;
import com.alibaba.fastjson2.reader.ObjectReader;
import com.nsl.my_youlai.common.base.IBaseEnum;
import lombok.extern.slf4j.Slf4j;

import java.lang.reflect.Type;
import java.util.Map;

@Slf4j
public class ColorEnumReader implements ObjectReader<ColorEnum> {
    @Override
    public ColorEnum readObject(JSONReader jsonReader, Type type, Object fieldName, long l) {
        //String s=jsonReader.readString();


        Map<String,Object> map=jsonReader.readObject();
        if(map==null){
            return null;
        }
        Object value=map.get("value");
        log.info("type = {}",type);
        log.info("fieldName= {}",fieldName);
        log.info("value= {}",value);


        ColorEnum colorEnum= IBaseEnum.getEnumByValue(value,ColorEnum.class);
        return colorEnum;
    }
}
